//==========Ajax请求=============
function doPost(url, data, callback, isAsync){
    $.ajaxSetup( {
        beforeSend: function(xhr) {
            //xhr.setRequestHeader("token", $.cookie('token'));
        },
        error:function(xhr){
            console.log(xhr);
            var value=JSON.parse(xhr.responseText);
            if(value.code==400) {
                window.location.href = window.location.href.substring(0,window.location.href.length-1);
            }
        }
    });
    $.ajax({
        url:url,
        data:data,
        method:"post",
        success:callback,
        dataType:'json',
        async:isAsync,
    })
}

function doGet(url, data, callback, isAsync){
    $.ajaxSetup( {
        beforeSend: function(xhr) {
            //xhr.setRequestHeader("token", $.cookie('token'));
        },
        error:function(xhr){
            console.log(xhr);
            var value=JSON.parse(xhr.responseText);
            if(value.code==400) {
                window.location.href = window.location.href.substring(0,window.location.href.length-1);
            }
        }
    });
    $.ajax({
        url:url,
        data:data,
        method:"get",
        dataType:'json',
        async:isAsync,
        success:callback,
    })
}

function ajaxPostFile(url, params, callback) {
    $.ajax({
        type : 'post',
        url : url,
        data : params,
        contentType: false,
        processData: false,
        cache: false,
        success:callback,
    });
}
//异步
function AsyncPost(url, data, callback){
    doPost(url, data, callback, true);
}
function AsyncGet(url, data, callback){
    doGet(url, data, callback, true);
}

function SyncPost(url, data, callback){
    doPost(url, data, callback, false);
}

function SyncGet(url, data, callback){
    doGet(url, data, callback, false);
}